.. _Code_Sample: =============================== Setting Up pQCee SPP toolkit =============================== To use SPP toolkit Windows target, you can do the following: 1) Have Microsoft Visual Studio 2017 installed 2) Open a "x64 Native Tools Command Prompt" 3) Copy all files into a directory - sha256.h - sha256.c - pqspp.h - main.c - pqspp_sdk.dll.lib 4) Compile the code using "cl main.c sha256.c pqspp_sdk.dll.lib". It will result in main.exe created. 5) Execute main.exe, and expect to see the following output: Generated a secret key and a public key (DER encoded of length 91)! Signed a message; got a pq_proof of size 210982 bytes Successfully verified the signature and the preimage proof! ======================== pQCee main.c Code Sample ======================== .. code-block:: c // This is pQCee's main.c code sample #include "pqspp.h" #include "sha256.h" #include #include int main() { uint8_t *sk = NULL; uint8_t *pk = NULL; int pk_len = -1; // call PQSPP_keygen to generate a secret key, public key and the length of each key int ret = PQSPP_keygen(&sk, &pk, &pk_len); if (ret != PQSPP_OK) { printf("Error in keygen: %d\n", ret); return -1; } printf( "Generated a secret key and a public key (DER encoded of length %d)!\n", pk_len); // your message digest uint8_t message[4] = {0x01, 0x02, 0x03, 0x04}; // hash the message digest unsigned char hash[32]; SHA256_CTX ctx; sha256_init(&ctx); sha256_update(&ctx,message,sizeof(message)); sha256_final(&ctx,hash); uint8_t *ec_sig = NULL; int ec_sig_len = -1; uint8_t *pip = NULL; int pip_len = -1; // call PQSPP_sign_digest to sign the hashed message ret = PQSPP_sign_digest(sk, hash,sizeof(hash), &ec_sig, &ec_sig_len, &pip, &pip_len); if (ret != PQSPP_OK) { printf("Error in sign: %d\n", ret); PQSPP_free_memory(sk); PQSPP_free_memory(pk); return -2; } printf("Signed a message; got a pq_proof of size %d bytes\n", pip_len); // call PQSPP_verify_digest to verify the hashed message against its signature ret = PQSPP_verify_digest(pk, pk_len, hash, sizeof(hash), ec_sig, ec_sig_len, pip, pip_len); if (ret != PQSPP_OK) { printf("Error in verify: %d\n", ret); PQSPP_free_memory(sk); PQSPP_free_memory(pk); PQSPP_free_memory(ec_sig); PQSPP_free_memory(pip); return -3; } printf("Successfully verified the signature and the preimage proof!\n"); // call PQSPP_free_memory to free memories used during the signing process PQSPP_free_memory(sk); PQSPP_free_memory(pk); PQSPP_free_memory(ec_sig); PQSPP_free_memory(pip); return 0; }